home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / superv22.zip / SUPERCOM.PAS < prev   
Pascal/Delphi Source File  |  1987-01-23  |  14KB  |  474 lines

  1. {                       SUPERCOM
  2.  
  3. Buffered communications support library for Turbo Pascal
  4.  
  5. (C) Copyright 1986, 1987 by Doctor Debug/ Steel City Software
  6.  
  7. These routines are meant to be called by user programs. The
  8. SUPERCOM.COM Interrupt 14 driver must have been installed to
  9. use any of these routines. Use of these routines without proper
  10. installation of SUPER.COM will produce unpredictable results.
  11.  
  12. The integers InError and OutError will always contain the error
  13. conditions after every receive or transmit. The bits of these
  14. values are defined as:
  15.  
  16.      Bit 7 (128)        Timeout
  17.      Bit 3   (8)        Framing Error
  18.      Bit 2   (4)        Parity Error
  19.      Bit 1   (2)        Overrun Error
  20.  
  21. If the value of InError[port] is 0, then you can be sure that the
  22. last character was received without error.
  23.  
  24. The value or Port is always 1 or 2 (which gets translated to 0 or
  25. 1 - I love IBM).
  26.  
  27.      Procedure InitPort(port,Baud,Parity,data_bits,stop_bits)
  28.           Baud: integer 300-9600
  29.           Parity: char, E(ven),O(dd),N(one)
  30.           Data_bits: integer, 7 or 8
  31.           Stop_bits: integer, 1 or 2
  32.  
  33.           This routine initializes the communications port
  34.           to the parameters specified and activates SUPERCOM
  35.           for that port. All of the following functions will
  36.           use the port specified here.
  37.  
  38.      Function PortStatus(port)
  39.  
  40.           This function returns the line status and modem control
  41.           status of the comm port specified. The bits returned are
  42.           defined as:
  43.  
  44.           Bit 15 (negative)  Time out (no device connected)
  45.           Bit 14 (16384)     Transmission shift register empty
  46.           Bit 13 (8192)      Transmission holding register empty
  47.           Bit 12 (4096)      Break detect
  48.           Bit 11 (2048)      Framing error
  49.           Bit 10 (1024)      Parity error
  50.           Bit 9  (512)       Overrun error
  51.           Bit 8  (256)       Data ready
  52.           Bit 7  (128)       Received line signal detect
  53.           Bit 6  (64)        Ring indicator
  54.           Bit 5  (32)        Data set ready
  55.           Bit 4  (16)        Clear to send
  56.           Bit 3  (8)         Delta receive line signal detect
  57.           Bit 2  (4)         Trailing edge ring detector
  58.           Bit 1  (2)         Delta data set ready
  59.           Bit 0  (1)         Delta clear to send
  60.  
  61.      Procedure XmitCh(ch)
  62.  
  63.           This Procedure sends the character in ch out the port
  64.           specified.
  65.  
  66.      Procedure XmitBlk(string)
  67.  
  68.           This procedure sends the entire string out the comm port.
  69.  
  70.      Procedure XmitLn(string)
  71.  
  72.           This is identical to XmitBlk, but adds a CR/LF to the
  73.           end of the block.
  74.  
  75.       Procedure RecCh(ch)
  76.  
  77.           This procedure waits until a character is available over
  78.           the comm line and then returns it in ch. If the system times
  79.           out ch will contain a nul (Ascii 0).
  80.  
  81.      Procedure RecLn(string)
  82.  
  83.           This is the equivalent of ReadLn over the comm port.
  84.           Be sure to check the InError variable to make sure the
  85.           operation did not time out (no CR was received.)
  86.  
  87.      Procedure RecBlk(number,String)
  88.  
  89.           The number of characters specified by number will be
  90.           placed into the string. Be sure to check the InError
  91.           variable to assure that the operation did not time out
  92.           before sufficient characters were received.
  93.  
  94.      Procedure GrabCh(ch)
  95.  
  96.           If a character is waiting in the receive buffer it will
  97.           be returned in ch otherwise ch will contain a nul character.
  98.  
  99.      Procedure PeekBuff(ch)
  100.  
  101.           Identical to GrabCh but the character is not removed
  102.           from the buffer.
  103.  
  104.      Procedure ClearBuff
  105.  
  106.           Empties the receive buffer
  107.  
  108.      Procedure ClosePort
  109.  
  110.           Closes the comm port and deactivates SUPERCOMM until the
  111.           next InitPort.
  112.  
  113.      Function Rlen
  114.  
  115.           Returns the number of characters currently available in the
  116.           receive buffer.
  117.  
  118.      Function SuperComPresent
  119.  
  120.           Returns True if Supercom loaded, false otherwise
  121.  
  122.      Procedure KillPort;
  123.  
  124.           Same as ClosePort, but SuperCom will have to be reloaded
  125.           in order to use any of the functions. SUPER is removed
  126.           totally from the interrupt chain.
  127.  
  128.      Procedure ChangePort(Port);
  129.  
  130.           A call to this procedure changes the SUPERCOM port
  131.           to the one specified.
  132.  
  133. *************************************************************************
  134.                    GLOBAL VARIABLES
  135. *************************************************************************
  136. }
  137.  
  138.    Type
  139.       _Register_Set = Record case Integer of
  140.                    1: (AX,BX,CX,DX,BP,DI,SE,DS,ES,Flags: Integer);
  141.                    2: (AL,AH,BL,BH,CL,CH,DL,DH: Byte);
  142.                    End;
  143.  
  144. (* NOTE: Make LSTRING whatever type string you want. For strings greater
  145.    that 255 you will have to make this an array of characters, and adjust
  146.    the other routines accordingly. The first version of these routines
  147.    used a 1024 byte monster, but using a 255 byte string will make your
  148.    application much more manageable *)
  149.  
  150.       LString = String[255];
  151.  
  152.       _Parity = (None,Even,Odd);
  153.  
  154.    Var
  155.       _Regs: _Register_Set;
  156.       InError,OutError:   Byte;
  157.       UsePort: Integer;
  158.  
  159. {***********************************************************************
  160.                             InitPort
  161. ***********************************************************************}
  162.  
  163.    Procedure InitPort(Port,Baud: integer;Par: _parity;D_bits,S_bits: integer);
  164.  
  165.    Var
  166.       Parameter: integer;
  167.  
  168.    Begin
  169.       Case Baud of
  170.          110: Baud := 0;
  171.          150: Baud := 1;
  172.          300: Baud := 2;
  173.          600: Baud := 3;
  174.         1200: Baud := 4;
  175.         2400: Baud := 5;
  176.         4800: Baud := 6;
  177.         Else  Baud := 7; {default to 9600}
  178.       End;
  179.  
  180.       If S_bits=2 then S_bits := 1
  181.          else S_bits := 0; {default 1 stop bit}
  182.  
  183.       If D_bits=7 then D_bits := 2
  184.          else D_bits := 3; {default 8 data bits}
  185.  
  186.       Parameter := (Baud shl 5) + (S_bits shl 2) + D_bits;
  187.       Case Par of
  188.          Odd:  Parameter := Parameter + 8;
  189.          Even: Parameter := Parameter + 24;
  190.          Else; {default no parity}
  191.       End;
  192.  
  193.       With _Regs do
  194.          Begin
  195.             AH := 12;         {Activate SuperCom}
  196.             AL := Parameter;  {set-up parameters}
  197.             DX := Port-1;     {port to use}
  198.             Intr($14,_Regs);  {perform function}
  199.          End;
  200.       UsePort := Port-1;      {Save for later use}
  201.    End; {InitPort}
  202.  
  203. {*************************************************************************
  204.                               Changeport
  205. **************************************************************************}
  206.  
  207. Procedure ChangePort(p:integer);
  208. Begin
  209.    With _Regs do
  210.    Begin
  211.       DX := p-1;
  212.       AH := 9;
  213.       Intr($14,_Regs);
  214.    End;
  215. End;
  216.  
  217. {**************************************************************************
  218.                               ClearBuff
  219. **************************************************************************}
  220.  
  221.    Procedure ClearBuff;
  222.    Begin
  223.       With _Regs do
  224.       Begin
  225.          DX := UsePort;
  226.          AH := 4;
  227.          Intr($14,_Regs);
  228.       End;
  229.    End;
  230.  
  231. {***************************************************************************
  232.                               ClosePort
  233. ***************************************************************************}
  234.  
  235.    Procedure ClosePort;
  236.    Begin
  237.       WIth _Regs do
  238.       Begin
  239.          DX := UsePort;
  240.          AH := 13;
  241.          Intr($14,_Regs);
  242.       End;
  243.    End;
  244.  
  245. {***************************************************************************
  246.                              Port Status
  247. ***************************************************************************}
  248.  
  249.    Function PortStatus:integer;
  250.    Begin
  251.       With _Regs do
  252.          Begin
  253.             AH := 3;              {Status Request}
  254.             DX := UsePort;
  255.             Intr($14,_Regs);
  256.             PortStatus := AX;
  257.